package com.bj58.mis.apm.server.core.common.result;

import java.util.List;

/**
 * @author: zhangfx
 * @create: 2018-06-19 17:29
 **/
public class SimplePage<T> implements Page<T> {
    private long total;

    private List<T> records;

    private int page;

    private int limit;

    public SimplePage(long total, List<T> records){
        this.total = total;
        this.records = records;
    }


    public SimplePage(long total, List<T> records, int page, int limit){
        this.total = total;
        this.records = records;
        this.page = page;
        this.limit = limit;
    }

    @Override
    public long getTotal() {
        return this.total;
    }

    @Override
    public List<T> getRecords() {
        return records;
    }

    @Override
    public int getPage() {
        return this.page;
    }

    @Override
    public int getLimit() {
        return this.limit;
    }

    @Override
    public int getPrePage() {
        return page > 1 ? page-1 : 1;
    }

    @Override
    public int gerNextPage() {
        return this.page < this.getTotalPage() ? this.page+1 : this.getTotalPage();
    }

    @Override
    public int getTotalPage() {
        if(limit == 0) return 0;

        if(total % limit == 0){
            return (int)(total/limit);
        }else{
            return (int)(total/limit) + 1;
        }
    }



    public void setTotal(long total) {
        this.total = total;
    }

    public void setRecords(List<T> records) {
        this.records = records;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public void setLimit(int limit) {
        this.limit = limit;
    }
}
